const Controller=require("egg").Controller
const PageModel=require("../model/PageModel");
const MessageBox=require("../utils/MessageBox");

class AdminInfoController extends Controller{

    async index(){
        let menuConfig=require("../../config/menuConfig");
        await this.ctx.render("adminInfo/index",{menuConfig});
    }

    async list(){
       let result = await this.ctx.service.adminInfo.getListByPage(this.ctx.request.query);
       await this.ctx.render("adminInfo/list",{
        adminInfoList:result[0],
        pageModel:new PageModel(result[1][0].totalCount,this.ctx.request.query.pageIndex||1)
       });
    }
    async addAdminInfo(){
        await this.ctx.render("adminInfo/addAdminInfo");
    }

    async doAddAdminInfo(){
        let flag= await this.ctx.service.adminInfo.addAdminInfo(this.ctx.request.body);
        if(flag){
            this.ctx.body=MessageBox.alertAndRedirect("添加成功","/adminInfo/list");
        }
        else{
            this.ctx.body=MessageBox.alertAndBack("添加失败");
        }
    }

    async checkAdminId(){
       let flag=await this.ctx.service.adminInfo.checkAdminId(this.ctx.request.query.adminid);
       this.ctx.body=flag;
    }

    async logOut(){
        this.ctx.success.destory();
        await this.ctx.redirect("/");
    }
}

module.exports=AdminInfoController;